# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:chrome_test.py
@Time:2024/10/11 15:50

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from time import sleep

def convert_to_seconds(time_str):
    # 分割字符串获取分钟和秒
    parts = time_str.split('分')
    minutes = int(parts[0])  # 将分钟转换为整数
    seconds = int(parts[1].replace('秒', ''))  # 移除"秒"并转换为整数

    # 将分钟转换为秒，并加上秒
    total_seconds = minutes * 60 + seconds
    return total_seconds


# 指定 ChromeDriver 的路径
driver_path = 'd:/code_zgq/ganbu/chromedriver.exe'
service = Service(executable_path=driver_path)

# 创建 WebDriver 实例
driver = webdriver.Chrome(service=service)
# driver = webdriver.Chrome()



driver.implicitly_wait(3)
driver.maximize_window()

# 打开网页
driver.get('https://www.sxgbxx.gov.cn/login')

# 等待页面加载完成
wait = WebDriverWait(driver, 10)

# 找到用户名输入框并输入用户名
username_input = wait.until(EC.presence_of_element_located((By.ID, 'userEmail')))
username_input.send_keys('u0122092')

# 找到密码输入框并输入密码
password_input = wait.until(EC.presence_of_element_located((By.ID, 'userPassword')))
password_input.send_keys('071726zgq001!')

# 提示用户输入验证码
# print("按回车继续...")
input("按回车继续...")
# 找到登录按钮并点击
# login_button = wait.until(EC.element_to_be_clickable((By.XPATH, '//a[@title="立即登录"]')))
# login_button.click()

# 请注意，验证码通常需要手动输入，或者使用第三方服务来识别验证码
# 如果页面上有验证码输入框，你可能需要手动输入或使用其他方法来处理

# 完成操作后关闭浏览器
# driver.quit()
# driver.get('https://www.sxgbxx.gov.cn/')
# # 专题培训
# # divs_zt = driver.find_element(By.CSS_SELECTOR,"div[class='net-cou-box']")
# divs_zt = driver.find_element(By.CSS_SELECTOR,"div.net-cou-box")
# # 根据属性选择元素
#
# elements = divs_zt.find_elements(By.CSS_SELECTOR, '[href]')
# for element in elements:
#     print(element.get_attribute('outerHTML'))
#
# #aCoursesList > div.container > div.mt30.m-top-box.tzc_zt_dbox
#
# driver.get("https://www.sxgbxx.gov.cn/front/planInfoDetails?planId=7baa61f923a0e652")
# baoming = driver.find_element(By.CSS_SELECTOR, "#aCoursesList > div > div.i-box.clearfix.pr.of.mt20.m-video-box > article.fl.c-a-wrap.cou-a-wrap > div > div.mt20.clearfix.of > div > a")
# #如果还未报名，点击
# if baoming:
#     baoming.click()
# driver.get("https://www.sxgbxx.gov.cn/uc/plan/info?id=7baa61f923a0e652")
# kecheng_ul = driver.find_element(By.CSS_SELECTOR, 'div.p-cou-wrap.p-l-module > ul')
#
# print(kecheng_ul.get_attribute("outerHTML"))
# kecheng = kecheng_ul.find_elements(By.CSS_SELECTOR,'li')
# # for kecheng in kecheng_ul:
# #     print(kecheng.get_attribute("outerHTML"))
#
# for item in kecheng:
#     print(item.get_attribute("outerHTML"))
# 登录后可直达网址
driver.get("https://www.sxgbxx.gov.cn/front/playkpoint/b836c3aaf19abca4")
play = driver.find_element(By.CSS_SELECTOR,"div.pv-cover > span")
play.click()
duration = driver.find_element(By.CSS_SELECTOR,"#kp_1 > div > a.play-icon-box > small")#kp_1 > div > a.play-icon-box > small
print(duration.text)

sleep(convert_to_seconds(duration.text)+3)
# 播放完，再开始下一个
play = driver.find_element(By.CSS_SELECTOR,"div.pv-cover > span")
play.click()
input('...')




